{extend name="public:base" /}
{block name="content"}
<div class="page-header">
	<h1>
		{$breadcrumb1}
		<small>
			<i class="ace-icon fa fa-angle-double-right"></i>
			{$crumbs}
		</small>
	</h1>
</div>
<div class="row">
	<div class="col-xs-12">
		<div class="panel-body">
			<form action="{:url('Free/first_info')}" method="post" enctype="multipart/form-data" id="form-goods" class="form-horizontal">
				<ul class="nav nav-tabs">
					<li class="active"><a href="#tab-data" data-toggle="tab">合约信息</a></li>
					<li><a href="#tab-links" data-toggle="tab">买入信息</a></li>
					<li><a href="#tab-option" data-toggle="tab">卖出信息</a></li>
				</ul>
				<div class="tab-content">
					<!-- 合约信息 START -->
					<div class="tab-pane active" id="tab-data">
						<input type="hidden" name="id" value="{$info.id}" />
						<table class="table table-bordered">
							<tr>
								<td style="width: 20%">ID</td>
								<td>{$info.id}</td>
							</tr>
							<tr>
								<td>用户</td>
								<td>{$info.username}</td>
							</tr>
							<tr>
								<td>姓名</td>
								<td>{:get_member_idcardname($info.username)}</td>
							</tr>
							<tr>
								<td>申请金额</td>
								<td>{$info.money}</td>
							</tr>
							<tr>
								<td>合约开始时间</td>
								<td>{$info.begin_day}</td>
							</tr>
							<tr>
								<td>合约结束时间</td>
								<td>{$info.end_day}</td>
							</tr>
						</table>
					</div>
					<!-- 合约信息 END -->
					<!-- 买入信息 START -->
					<div class="tab-pane" id="tab-links">
						<table class="table table-bordered">
							<tr>
								<td style="width: 7%">交易所</td>
								<td>{:get_trade_name($info.exchange)}</td>
							</tr>
							<tr>
								<td>交易品种</td>
								<td>{:get_variety_name($info.exchange_variety)}</td>
							</tr>
							<tr>
								<td>买入枚数</td>
								<td>{$info.b_num}</td>
							</tr>
							<tr>
								<td>买入规定时间</td>
								<td>{$info.begin_day}</td>
							</tr>
							<tr>
								<td>买入的实际时间</td>
								<td><input style="width:400px;" type="date" id="b_real_date" name="b_real_date" value="{$info.b_real_date}" /></td>
							</tr>
							<tr>
								<td style="border-left: none;">买入价格录入</td>
								<td id="none" style="border-left: none;border-right: none; width: 28%; display: none">
									<a href="#" id="AddMoreFileBox_b" class="btn btn-info">添加买入信息框</a></p>
									<div id="InputsWrapper_b">
										<div>
											<input type="number" name="b_num[]" class="field_1" value="" placeholder="请输入买入枚数" />
											<input type="number" step="0.01" name="b_price[]" class="field_1" value="" placeholder="请输入买入单价" />
											<a href="#" class="removeclass">×</a>
										</div>
									</div>
								</td>
								<td id="none2">
									枚数：{$info.b_num}
									总价：{$info.b_price}
									&nbsp;&nbsp;&nbsp;
									<button type="button" class="btn btn-info" id="block">修改</button>
								</td>
							</tr>
							<tr>
								<td>审批意见</td>
								<td><textarea id="b_desc"  name="b_desc" type="text" style="width:400px;" value="" /></textarea>
								</td>
							</tr>
							<tr>
								<td>买入凭证上传</td>
								<td>
									<a href="{:url('Free/do_upload',['id'=>$info['id'],'seq_id'=>1])}" type="button" class="btn btn-primary" style="width:400px;" >点击添加图片</a>
								</td>
							</tr>
							<tr>
								<td>买入凭证</td>
								<td style="border-right: none;">
									{volist name="b_img" id="b" }
									<!-- 模态框（Modal） -->
									<img src="{$b.img_path}" class="image" style="height: 100px; width: 100px">
									{/volist}
								</td>

							</tr>
							<tr>
								<td>操作</td>
								<td>
									<label class="radio-inline">
										<input type="radio" checked="checked" value="1" name="b_checked">审核通过</label>
									<label class="radio-inline">
										<input type="radio" value="2" name="b_checked">审核不通过</label>
								</td>
							</tr>
						</table>
					</div>
					<!-- 买入信息 END -->

					<!-- 卖出信息 START -->
					<div class="tab-pane" id="tab-option">
						<table class="table table-bordered">
							<tr>
								<td style="width: 7%">交易所</td>
								<td>{:get_trade_name($info.exchange)}</td>
							</tr>
							<tr>
								<td>交易品种</td>
								<td>{:get_variety_name($info.exchange_variety)}</td>
							</tr>
							<tr>
								<td>卖出枚数</td>
								<td>{$info.b_num}</td>
							</tr>
							<tr>
								<td>卖出规定时间</td>
								<td>{$info.end_day}</td>
							</tr>
							<tr>
								<td>卖出的实际时间</td>
								<td><input style="width:400px;" type="date" id="s_real_date" name="s_real_date" value="{$info.end_day}" /></td>
							</tr>
							<tr>
								<td style="border-left: none;">卖出价格录入</td>
								<td style="border-left: none;border-right: none; width: 28%">
									<a href="#" id="AddMoreFileBox_s" class="btn btn-info">添加卖出信息框</a></p>
									<div id="InputsWrapper_s">
										<div>
											<input type="number" name="s_num[]" class="field_1" value="" placeholder="请输入卖出枚数" />
											<input type="number" step="0.01" name="s_price[]" class="field_1" value="" placeholder="请输入卖出单价" />
											<a href="#" class="removeclass">×</a>
										</div>
									</div>
								</td>
							</tr>
							<tr>
								<td>审批意见</td>
								<td><textarea id="s_desc"  name="s_desc" type="text" style="width:400px;" value="" /></textarea>
								</td>
							</tr>
							<tr>
								<td>卖出凭证上传</td>
								<td>
									<a href="{:url('Free/do_upload',['id'=>$info['id'],'seq_id'=>2])}" type="button" class="btn btn-primary" style="width:400px;" >点击添加图片</a>
								</td>
							</tr>
							<tr>
								<td>卖出记录凭证</td>
								<td style="border-right: none;">
									{volist name="s_img" id="s" }
									<!-- 模态框（Modal） -->
									<img src="{$s.img_path}" class="image" style="height: 100px; width: 100px">
									{/volist}
								</td>

							</tr>
							<tr>
								<td>操作</td>
								<td>
									<label class="radio-inline">
										<input type="radio" checked="checked" value="1" name="s_checked">审核通过</label>
									<label class="radio-inline">
										<input type="radio" value="2" name="s_checked">审核不通过</label>
								</td>
							</tr>
						</table>
					</div>
					<!-- 卖出信息 END -->
				</div>
				<div class="form-group">
					<div style="margin-left:20px; margin-top: 20px">
						<input id="send" type="submit" value="提交" class="btn btn-primary" />
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<div id="outerdiv" style="position:fixed;top:0;left:0;background:rgba(0,0,0,0.7);z-index:2;width:100%;height:100%;display:none;">
	<div id="innerdiv" style="position:absolute;">
		<img id="bigimg" style="border:5px solid #fff;" src="" />
	</div>
</div>
{/block}
{block name="javascript"}

<script src="__PUBLIC__/js/ckeditor/ckeditor.js"></script>
<script>
	function gosearch()
	{
		if(window.event.keyCode == 13)
		{
			search();
			return false;
		}
	}

	$(function none(){
		var sell = <?php echo  json_encode($b_sell);   ?>;

		console.log(sell);

		if(sell == '' || sell == null || sell == undefined){
			$('#none').css('display','block');
			$('#none2').css('display','none');
		}
	})

	$('#block').click(function(){
		$('#none').css('display','block');
		$('#none2').css('display','none');
	});
</script>
<script>
	//买入价格录入
	$(document).ready(function() {
		var MaxInputs       	= 9; //maximum input boxes allowed
		var InputsWrapper_b   	= $("#InputsWrapper_b"); //Input boxes wrapper ID
		var AddButton_b       	= $("#AddMoreFileBox_b"); //Add button ID
		var x = InputsWrapper_b.length; //initlal text box count
		var FieldCount=1; //to keep track of text box added
		$(AddButton_b).click(function (e)  //on add input button click
		{
			if(x <= MaxInputs) //max input box allowed
			{
				FieldCount++; //text box added increment
				//add input box
				$(InputsWrapper_b).append('<div><input type="number" name="b_num[]" id="field_'+ FieldCount +'" value="" placeholder="请输入买入枚数"/>&nbsp;<input type="number" step="0.01" name="b_price[]" id="field_'+ FieldCount +'" value="" placeholder="请输入买入单价"/>&nbsp;<a href="#" class="removeclass">×</a></div>');
				x++; //text box increment
			}
			return false;
		});
		$("body").on("click",".removeclass", function(e){ //user click on remove text
			if( x > 1 ) {
				$(this).parent('div').remove(); //remove text box
				x--; //decrement textbox
			}
			return false;
		})
	});
</script>
<script>
	//卖出价格录入
	$(document).ready(function() {
		var MaxInputs       	= 9; //maximum input boxes allowed
		var InputsWrapper_s   	= $("#InputsWrapper_s"); //Input boxes wrapper ID
		var AddButton_s       	= $("#AddMoreFileBox_s"); //Add button ID
		var x = InputsWrapper_s.length; //initlal text box count
		var FieldCount=1; //to keep track of text box added
		$(AddButton_s).click(function (e)  //on add input button click
		{
			if(x <= MaxInputs) //max input box allowed
			{
				FieldCount++; //text box added increment
				//add input box
				$(InputsWrapper_s).append('<div><input type="number" name="s_num[]" id="field_'+ FieldCount +'" value="" placeholder="请输入卖出枚数"/>&nbsp;<input type="number" step="0.01" name="s_price[]" id="field_'+ FieldCount +'" value="" placeholder="请输入卖出单价"/>&nbsp;<a href="#" class="removeclass">×</a></div>');
				x++; //text box increment
			}
			return false;
		});
		$("body").on("click",".removeclass", function(e){ //user click on remove text
			if( x > 1 ) {
				$(this).parent('div').remove(); //remove text box
				x--; //decrement textbox
			}
			return false;
		})
	});
</script>
<script type="text/javascript">
	//图片预览
	$('.image').click(function(){
		var _this = $(this);							//将当前的pimg元素作为_this传入函数
		imgShow("#outerdiv", "#innerdiv", "#bigimg", _this);

	});
	function imgShow(outerdiv, innerdiv, bigimg, _this) {
		var src = _this.attr("src");					//获取当前点击的pimg元素中的src属性
		$(bigimg).attr("src", src);						//设置#bigimg元素的src属性

		/*获取当前点击图片的真实大小，并显示弹出层及大图*/
		$("<img/>").attr("src", src).load(function () {
			var windowW = $(window).width();			//获取当前窗口宽度
			var windowH = $(window).height();			//获取当前窗口高度
			var realWidth = this.width;					//获取图片真实宽度
			var realHeight = this.height;				//获取图片真实高度
			var imgWidth, imgHeight;
			var scale = 0.8;							//缩放尺寸，当图片真实宽度和高度大于窗口宽度和高度时进行缩放

			if (realHeight > windowH * scale) {			//判断图片高度
				imgHeight = windowH * scale;			//如大于窗口高度，图片高度进行缩放
				imgWidth = imgHeight / realHeight * realWidth;		//等比例缩放宽度
				if (imgWidth > windowW * scale) {					//如宽度扔大于窗口宽度
					imgWidth = windowW * scale;						//再对宽度进行缩放
				}
			} else if (realWidth > windowW * scale) {				//如图片高度合适，判断图片宽度
				imgWidth = windowW * scale;							//如大于窗口宽度，图片宽度进行缩放
				imgHeight = imgWidth / realWidth * realHeight;		//等比例缩放高度
			} else {									//如果图片真实高度和宽度都符合要求，高宽不变
				imgWidth = realWidth;
				imgHeight = realHeight;
			}
			$(bigimg).css("width", imgWidth);			//以最终的宽度对图片缩放

			var w = (windowW - imgWidth) / 2;			//计算图片与窗口左边距
			var h = (windowH - imgHeight) / 2;			//计算图片与窗口上边距
			$(innerdiv).css({"top": h, "left": w});		//设置#innerdiv的top和left属性
			$(outerdiv).fadeIn("fast");					//淡入显示#outerdiv及.pimg
		});
		$('#outerdiv').click(function () {				//再次点击淡出消失弹出层
			$(this).fadeOut("fast");
		});
	}
</script>
<script>

	$('#send').click(function(){

		var b_checked = $('input[name="b_checked"]:checked ').val();		//买入
		var s_checked = $('input[name="s_checked"]:checked ').val();  		//卖出

		var s_real_date		=	$('input[name="s_real_date"]').val();		//卖出实际时间

		var s_num			=	$('input[name="s_num[]"]').val();			//卖出枚数

		var s_price			=	$('input[name="s_price[]"]').val();			//卖出价格

		if(b_checked != 2 && s_checked != 2){

			if(s_real_date == ''){
				alert('卖出实际时间必填');
				return false;
			}
			if(s_num == ''){
				alert('卖出枚数必填');
				return false;
			}
			if(s_price == ''){
				alert('卖出价格必填');
				return false;
			}
		}

	});
</script>
{/block}
